package kpi.java_training.domain.questions;

import java.util.List;

abstract public class Question {
    private String textOfQuestion;
    private List<String> answerVariants;
    protected String correctAnswer;
    private int complexity;

    public Question(String textOfQuestion, List<String> answerVariants, String correctAnswer, int complexity) {
        this.textOfQuestion = textOfQuestion;
        this.answerVariants = answerVariants;
        this.correctAnswer = correctAnswer;
        this.complexity = complexity;
    }

    protected String getExplanationText() {
        return "Choose answer";
    }

    @Override
    public String toString() {
        String s = String.format("Complexity %d\n%s\n%s", complexity, getExplanationText(), textOfQuestion);
        if (!answerVariants.equals("")) {
            s = String.format("%s\n%s", s, answerVariants);
        }
        return s;
    }

    public int getComplexity() {
        return complexity;
    }

    public boolean parseUserAnswer(String userAnswer) {
        return userAnswer.equals(correctAnswer);
    }

    abstract protected String getType();

    public QuestionData getSaveData() {
        return new QuestionData(getType(), textOfQuestion, answerVariants, correctAnswer, String.valueOf(complexity));
    }
}